﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestVisioCanvas.Pages
{
    /// <summary>
    /// Interaction logic for ProductDetailsPage.xaml
    /// </summary>
    public partial class ProductDetailsPage : PageFunction<String>
    {
        BitmapImage bg = new BitmapImage();
        public ProductDetailsPage()
        {
            InitializeComponent();
        }

        public ProductDetailsPage(Models.ProductDetailsModel model)
        {
            InitializeComponent();
            this.DataContext = model;
            bg.BeginInit();
            bg.UriSource = new Uri(Environment.CurrentDirectory + "//Images//CurrentBackground.png");
            // saves the image as cache, but after the first use it discard it
            bg.CacheOption = BitmapCacheOption.OnLoad;
            bg.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
            bg.EndInit();

            var bgBrush = new ImageBrush();
            bgBrush.ImageSource = bg;
            bgBrush.Opacity = 0.5;
            this.Background = bgBrush;
        }

        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            NavigationService.GoBack();
        }

        public void ChangeProduct(Models.ProductDetailsModel model)
        {
            this.DataContext = model;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Background = null;
            NavigationService.GoBack();            
        }

        private void Button_TouchUp(object sender, TouchEventArgs e)
        {
            this.Background = null;
            NavigationService.GoBack();
        }
    }
}
